<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>添加新的商品</title>
<script language="javascript">
//$.validator.setDefaults({
//    submitHandler: function() {
//      $("#otherForm").submit();
//    }
//});
$().ready(function() {
	$("#sku").focus();
    $("#otherForm").validate();
});

$.validator.setDefaults({
  submitHandler: function(form) { form.submit(); }
});
function JqValidate()  
{  
    return $( '#otherForm' ).validate();  
}  
function submitBtn()  
{  
     if( JqValidate()){ 
	 //	alert(1);
         $( '#otherForm' ).submit();  
    }  
}  
/*function showinput_pro()
{
	var sku = $("#sku").val();
	var goodstypeID = $("#goodstypeID").val();
$.post("/product/ajaxbutton", {"op": "showattr","id":goodstypeID},function(data){
			if(data !=201)
			{
				for(var s=0;s<data.length;s++)
				{
					attr+=data[s].attr_name;
					str+="<td>"+attr+"</td>";
				}
				alert(str);
			}
	   },"json");	
}*/
var totalnum = 1;
function showinputPro()
{
	var inputn = document.getElementById("showsuppliertd");
	var str=inputn.innerHTML;
	var num=1;
	var tonum = 1;
	for(var i=1;i<=num;i++){
		tonum=tonum+i;
		str += "<tr id=las"+tonum+">";
		str+="<td class=\"head1\" width=\"10%\">采购商家名称</td>";
		str+="<td class=\"head0\" width=\"40%\"><input id=\"businessman\" name=\"businessman[]\" class=\"width200\" type=\"text\"></td>";
        str+="<td class=\"head1\" width=\"10%\">采购连接</td>";
		str+="<td class=\"head0\"><input id=\"businessmanline\" name=\"businessmanline[]\" class=\"width400\" type=\"text\"></td>";
		 str+="<td>&nbsp;&nbsp;<a href=javascript:void(0) onclick=delfileinput("+tonum+")><span style=\"padding:5px 0 0\" class=\"c9\">移除</span></a></td>";
        str+="</tr>";
	}
	$("#showsuppliertd").before(str);
	
}
function showinput()
{
	var inputn = document.getElementById("input1");
	var str=inputn.innerHTML;
	var num=1;
	var sku = $("#sku").val();
	var attr="";
	var goodstypeID = $("#goodstypeID").val();
	
	for(var i=1;i<=num;i++){
		totalnum=totalnum+i;
		str += "<tr class=\"italic\" id=las"+totalnum+">";
		str+="<td><input type=\"text\" name=\"subsku[]\" style=\"text-transform:uppercase;\" id=\"subsku\" value=\""+sku+"\" class=\"width200\"></td>";
		if(goodstypeID)
		{
			$.ajaxSetup({async: false});	//同步
			$.post("/product/ajaxbutton", {"op": "showattr","id":goodstypeID},function(data){
					if(data !=201)
					{
						for(var s=0;s<data.length;s++)
						{
							attr+="<td>"+data[s].attr_name+"</td>";
							if(data[s].attr_input_type==0)
							{
								attr+="<td><input type=\"text\" name=attr_values"+data[s].attr_id+"[] id=attr_values"+data[s].attr_id+" class=\"width100\"></td>";	
							}else{
								var words = data[s].attr_values.split('\r\n');
								if(data[s].attr_values_code){
									var wordscode= data[s].attr_values_code.split('\r\n');
								}else{
									var wordscode="";	
								}
								 var tmpwords="<select name=attr_values"+data[s].attr_id+"[] id=attr_values"+data[s].attr_id+" class=\"selection\" style=\"width:200px;\" onchange=\"getcode(this,"+totalnum+")\">";
								 tmpwords+='<option value="" code="99999999AA">请选择</option>';
								for(var k=0;k<words.length;k++)
								{
									if(wordscode=='')
									{
										tmpwords+=" <option value=\""+words[k]+"\" code='99999999AA'>"+words[k]+"</option>";
									}else{
										tmpwords+=" <option value=\""+words[k]+"\" code=\""+wordscode[k]+"\">"+words[k]+"</option>";	
									}
									
								}
								tmpwords+=" </select>";
								attr+="<td>"+tmpwords+"</td>";
							}
							
						}
						
					}
			   },"json");		
		}
		
		str+=attr;
		str+="<td><input type=\"file\" name=\"userfile[]\" id=\"userfile\"  class=\"width200\"></td>";
        str+="<td>&nbsp;&nbsp;<a href=javascript:void(0) onclick=delfileinput("+totalnum+")><span style=\"padding:5px 0 0\" class=\"c9\">移除</span></a></td>";
        str+="</tr>";
	}
	$("#input1").before(str);
	
}
function getcode(obj,sut)
{
	var sku = $("#sku").val();
	if(sku=="")
	{
		$("#skuerr").html('<br /><span style="color:#ff0000;">请填写SKU</span>');
		$("#sku").focus();
		return false;	
	}
	//获取tr中的值 
	var skuID = "";
   $("#las"+sut+" select").each(function()
   { 
      var st= $(this).find("option:selected").attr("code");//遍历获取自定义的值；
	  if(st =='99999999AA')
	  {
		  
	  }else{
		skuID+=st+"-";  
	  }
   });
   //去除最后一个
    if(skuID){
    var skuID = skuID.substr(0,skuID.length-1);//除去最后一个“，”
	skuID = sku+"-"+skuID;
	$("#las"+sut+" input").val(skuID);
   }
	return;
}

function delfileinput(id)
{
	if(confirm("确定移除？"))
	{
		$("#las"+id).remove();
	}
}
function cleart()
{
	$("tr").remove(".italic");
}
function getSku()
{
	
	var sku = $("#sku").val();
	if(sku){
		$("#skuerr").html('<img src="/fuman/images/loaders/loader2.gif">');
	$.post("/product/ajaxbutton", {"op": "searchsku","sku":sku},function(data){
			if(data ==200)
			{
				$("#skuerr").html('');
			}else{
				$("#skuerr").html('<font color=red>SKU['+sku+']已经存在！</font>');
				$("#sku").val('');
			}
	   },"json");
	}
}
function issupplier()
{
	var supplier = $("#supplier").val();
	if(supplier == 3)
	{
		$("#showsupplier").show();
	}else{
		$("#showsupplier").hide();	
	}
}
</script>
<body class="withvernav">
<div class="bodywrapper"> {{include file='/public/leftmenu.tpl'}}
  <div class="centercontent">
    <div class="pageheader notab">
      <h1 class="pagetitle">添加新的商品</h1>
      <span class="pagedesc"></span>
      <div class="menulist">
        <ul class="profile_summary">
          <li class="current"><a href="/product/productlist">产品列表</a></li>
        </ul>
      </div>
    </div>
    <!--pageheader-->
    
    <div id="contentwrapper" class="contentwrapper">
      <div id="basicform" class="subcontent">
        <form class="stdform stdform2"  id="otherForm" method="post" action="/product/saveproduct" enctype="multipart/form-data" >
          <table cellpadding="0" cellspacing="0" border="0" class="stdtable">
            <thead>
              <tr>
                <th colspan="2" class="head1">一、基础信息</th>
              </tr>
            </thead>
          </table>
          <table cellpadding="0" cellspacing="0" border="0" class="stdtable">
            <tbody>
              <tr>
                <td class="head1" width="120">商品分类 *</td>
                <td class="head0" colspan="3"><select name="bigclassID" id="bigclassID" class="selection" style="width:200px;" onChange="getsecondcate()" required>
                    <option value="">请选择</option>
                    {{foreach from=$categorylist item=res key=key}}
                    <option value="{{$res.id}}" {{if $goods.g_bigclassid == $res.id}} selected{{/if}}>{{$res.cate_name}}</option>
                    {{/foreach}}
                  </select>
                &nbsp; <span id="showsecondcate"></span> &nbsp; <span id="showthirdcate"></span></td>
              </tr>
               <tr>
                <td class="head1">商品SKU *</td>
                <td colspan="3" class="head0"><input type="text" name="sku" id="sku" class="width200" value="{{$goods.goods_sku}}" onKeyUp="this.value=this.value.replace(/[^\w_\w-]/g,'');" required onBlur="getSku()"  style="text-transform:uppercase;">
                 <span id="skuerr"></span></td>
              </tr>
               <tr>
                <td class="head1">商品名称 *</td>
                <td colspan="3" class="head0"><input type="text" name="goods_name" class="width400" value="{{$goods.goods_name}}" required></td>
              </tr>
              <tr>
                <td class="head1">英文名称</td>
                <td colspan="3" class="head0"><input type="text" name="en_goods_name" class="width400" value="{{$goods.en_goods_name}}"></td>
              </tr>
               
              <tr>
                <td class="head1" width="10%">重量(克) *</td>
                <td class="head0" width="40%"><input type="text" name="weight" class="width100" value="{{$goods.g_weight}}" required></td>
                <td class="head0" width="120">成本价格（元） *</td>
                <td class="head1"><input type="text" name="costprice" class="width100" value="{{$goods.g_costprice}}" required></td>
              </tr>
             
              
             
               <tr>
                <td class="head1">销售状态 *</td>
                <td class="head0"><select class="selectCss2" name="sale_status" id="sale_status" required>
                    <option value="">请选择</option>
                    {{foreach from=$salestatus item=res key=key}}
                    <option value="{{$key}}" {{if  ($key==4 || $key==5 || $key==2 || $key==3 || $key==6)}}style="display:none"{{/if}} {{if 1==$key}} selected="selected"{{/if}}> {{$res}} </option>
                    {{/foreach}}
                   
                  </select></td>
                <td class="head1">商品属性<span class="head0">*</span></td>
                <td class="head0"><select name="goodstypeID" id="goodstypeID" class="selection" style="width:200px;" onChange="cleart()" required>
                    <option value="">请选择</option>
                    
                    {{foreach from=$attribute item=res key=key}}
                    
                    <option value="{{$res.cat_id}}">{{$res.cat_name}}</option>
                    
                    {{/foreach}}
                  
                  </select></td>
              </tr>
             
                <tr>
                  <td class="head1">采购员<span class="head0">*</span></td>
                  <td class="head0"><select name="buyer" id="buyer" class="selection select2_group" style="width:200px;"  required>
                    <option value="">请选择</option>
                    
                      {{foreach from=$userlist item=res key=key}}
                    
                    <option value="{{$res.name}}">{{$res.name}}</option>
                    
                    {{/foreach}}
                  
                  </select></td>
                  <td class="head1">开发人员 <span class="head0">*</span></td>
                <td class="head0"><select name="checkman" id="checkman" class="selection select2_group" style="width:200px;" required>
                    <option value="">请选择</option>
                    
                    {{foreach from=$userlist item=res key=key}}
                    
                    <option value="{{$res.name}}">{{$res.name}}</option>
                    
                    {{/foreach}}
                  
                  </select></td>
                </tr>
                  <tr>
                 <td class="head1">供货商<span class="head0">*</span></td>
                 <td class="head0">
                 <select name="supplier" id="supplier" onChange="issupplier()" class="selection" style="width:200px;" required>
                    <option value="">请选择</option>
                    {{foreach from=$factory item=res key=key}}
                    <option value="{{$res.id}}">{{$res.name}}</option>
                    {{/foreach}}
                  </select></td>
                 <td class="head1">申报价值(元)</td>
                 <td class="head0"><input type="text" name="pd_declare_value" class="width100" value="{{$goods.g_pd_declare_value}}" ></td>
               </tr>
              
               <tr>
                <td class="head1">采购天数</td>
                <td class="head0"><input type="text" name="procurement" class="width100" value="{{$goods.g_procurement}}"></td>
                <td class="head0" width="120">库存警戒天数</td>
                <td class="head1"><input type="text" name="inventory_day" class="width100" value="{{$goods.g_inventory_day}}" onKeyUp="this.value=this.value.replace(/[^1-9]/g,'');"></td>
              </tr>
               <tr>
                <td class="head1">商品品牌</td>
                <td class="head0"><input type="text" name="goods_brand" class="width100" value="{{$goods.goods_brand}}"></td>
                <td class="head0" width="120">零售价格（元）</td>
                <td class="head1"><input type="text" name="sellprice" class="width100" value="{{$goods.g_sellprice}}"></td>
              </tr>
                <tr>
                <td class="head1">质检标准</td>
                <td class="head0" colspan="3">
                <textarea name="standard" cols="10" rows="4">{{$res.standard}}</textarea>
                </td>
              </tr>
                <tr>
                <td class="head1">面料信息</td>
                <td class="head0" colspan="3">
                <textarea name="fabricinfo" cols="10" rows="4">{{$res.fabricinfo}}</textarea>
                </td>
              </tr>
               <tr>
                <td class="head1">备注信息</td>
                <td class="head0" colspan="3">
                <textarea name="memo" cols="10" rows="4">{{$res.memo}}</textarea>
                </td>
              </tr>
              
             </tbody>
           </table>
             {{if $goods.g_supplier==3}}
           <table cellpadding="0" cellspacing="0" border="0" class="stdtable"  style="display:none" id="showsupplier">
            <thead>
              <tr>
                <th colspan="6" class="head1">外采购供应商 &nbsp;&nbsp;<span style="margin-top:10px"><a href="javascript:void(0)"  onClick="showinputPro()"><img src="/fuman/images/add.png"></a></span></th>
              </tr>
            </thead>
             <tr>       
               <td class="head1" width="10%">采购商家名称</td>
                <td class="head0" width="40%"><input id="businessman" name="businessman[]" class="width200" type="text" required></td>
                <td class="head0" width="10%">采购连接</td>
                <td class="head1" colspan="2"><input id="businessmanline" name="businessmanline[]" class="width400" value="" type="text" required></td>
              </tr>
            <tbody id="showsuppliertd">
            </tbody>
          </table>
           {{/if}}
           
           
          <table cellpadding="0" cellspacing="0" border="0" class="stdtable">
            <thead>
              <tr>
                <th colspan="12" class="head1">二、子类商品 &nbsp;&nbsp;&nbsp;<span style="margin-top:10px"><a href="javascript:void(0)"  onClick="showinput()"><img src="/fuman/images/add.png"></a></span></th>
              </tr>
            </thead>
            <tbody id="input1">
            </tbody>
          </table>
          <table cellpadding="0" cellspacing="0" border="0" class="stdtable">
            <thead>
              <tr>
                <td><button type="submit" class="btn btn-primary" > 保存商品 </button>
               
                 </td>
              </tr>
              <tr>
                <th  class="head1">三、添加商品说明</span></th>
              </tr>
            </thead>
            <tbody>
              <tr>
                <td class="head0"> 第一步：填写好商品的SKU和商品属性，及其他基础信息；<br>
                  第二步：点击子类商品旁边的+号，添加子类商品。<br>
                  如SKU：11007777,属性选择服装：
                  该SKU 有2个颜色5个尺码，则生成10个子类商品;<br>
                  注意1：商品SKU只允许输入数字，大小写字母，中划线和下划线 <br>
                  注意2：遇到不选子类商品，系统默认自建同类型子商品，（针对11，12开头的工厂商品以及没有尺码信息的商品）</td>
              </tr>
            </tbody>
          </table>
        </form>
        <br />
      </div>
      <!--subcontent--> 
      
      <!--subcontent--> 
      
    </div>
    <!--contentwrapper--> 
    
  </div>
  <!-- centercontent --> 
  
</div>
<!--bodywrapper-->

</body>
</html>